import React, { Component } from 'react';

class User extends Component {

  constructor() {
    super();
    this.state = {
      // xing: '',
      // ming: ''
    }
  }

  handleInputChange =(e)=>{
    let name=e.target.name;
    this.setState({
      [name]:e.target.value
    })
  }

  render() {
    return (
      <div>
        姓：
        <input type="text" name="xing" 
         onChange={this.handleInputChange}
        defaultValue={this.state.xing} />
        <br></br>
        名：
        <input type="text" name="ming"
        onChange={this.handleInputChange}
        defaultValue={this.state.ming} />
        <hr />
        <p>
          欢迎您：{this.state.xing} {this.state.ming}
        </p>
      </div>
    );
  }
}

export default User;